package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ClassBean;
import com.project.bean.RoomBean;
import com.project.bean.StudentBean;
import com.project.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("stu")
public class StudentController {
    @Autowired
    private IStudentService stuService;

    @RequestMapping("findByItem")
    public IPage<StudentBean> findByItem(Integer pageNO, String stuName, String className, String roomAddress){
        return  stuService.findByItem(pageNO, stuName, className, roomAddress);
    }

    @RequestMapping("findById")
    public StudentBean findById(Integer stuId){
        return stuService.findById(stuId);
    }

    @RequestMapping("addStu")
    public String addStu(StudentBean stu,Integer classId,Integer roomId,String classname,String address){
        ClassBean classBean =new ClassBean();
        classBean.setClassId(classId);
        classBean.setClassName(classname);
        RoomBean roomBean = new RoomBean();
        roomBean.setRoomId(roomId);
        roomBean.setRoomAddress(address);
        stu.setStuRoom(roomBean);
        stu.setStuClass(classBean);
        stuService.addStu(stu);
        return "ok";
    }

    @RequestMapping("delStu")
    public String delStu(Integer stuId){
        stuService.delStu(stuId);
        return "ok";
    }
    @RequestMapping("changeRoom")
    public String changeRoom(Integer stuId,Integer roomId){
        stuService.changeRoom(stuId,roomId);
        return "ok";
    }
}
